// import express from "express";
const express = require("express");
// import { exec } from "../DBHelper";
const { exec } = require("../DBHelper");
const { author } = require("../Auth");

const ApiRouter = express.Router();

ApiRouter.get("/index", async function (req, res) {
  let result = await exec("select * from goods", []);
  res.json({
    msg: "查询成功",
    data: result,
  });
});
ApiRouter.post("/register", require("../controller/register").register);
ApiRouter.post("/login", require("../controller/users").login);

// /api/add  post
ApiRouter.post("/add", author(), require("../controller/cart").add);
//  xxx/:id --- > params.id
ApiRouter.get("/search/:gid", author(), require("../controller/goods").search);
ApiRouter.get(
  "/getBigimg/:gid",
  author(),
  require("../controller/goods").getBigimg
);
ApiRouter.get(
  "/getSmallimg/:gid",
  author(),
  require("../controller/goods").getSmallimg
);
//获取所有购物车
ApiRouter.get(
  "/getcarts/:uid",
  author(),
  require("../controller/cart").getcarts
);

ApiRouter.post("/modifiy", author(), require("../controller/cart").modifiy);
ApiRouter.post("/delete", author(), require("../controller/cart").delete);
ApiRouter.get("/getgoods", author(), require("../controller/goods").getgoods);
exports.ApiRouter = ApiRouter;
